<!-- 模板继承 -->
{extend name="public:base" /}

<!-- 页面标题 -->
{block name="title"}Administrator{/block}

<!-- 自定义css -->
{block name="css"}{/block}

<!-- 内容区域 -->
{block name="content"}
  <div class="nav-tabs-custom">
    <ul class="nav nav-tabs">
      <li class="active"><a href="#">{:lang('Document field')}</a></li>
      <li class=""><a href="{:url('admin/document_field/create')}">{:lang('Create')}</a></li>
      <li class=""><a href="{:url('admin/document_field/category')}">{:lang('Category')}</a></li>
    </ul>

    <div class="tab-content">
      <div class="box box-solid">
            <ul class="nav nav-pills">
                <li><a class="{empty name='search.cid'}text-red{/empty}" href="{:url('admin/document_field/index')}">{:lang('Any')}</a></li>
                {volist name="category" id="vo"}
                <li><a class="{eq name='search.cid' value='$vo.id'}text-red{/eq}" href="{:url('admin/document_field/index', ['cid' => $vo.id])}">{$vo.name}</a></li>
                {/volist}
            </ul>
      </div>

      <div class="tab-pane active table-responsive no-padding">
        <table class="table table-condensed table-hover">
            <thead>
                <tr>
                    <th>#ID</th>
                    <th>{:lang('Name')}</th>
                    <th>{:lang('Variable')}</th>
                    <th>{:lang('Type')}</th>
                    <th>{:lang('Sort')}</th>
                    <th>{:lang('Action')}</th>
                </tr>
            </thead>
            <tbody>
                {volist name="list" id="vo"}
                <tr id = "tr_{$vo.id}">
                    <td>{$vo.id}</td>
                    <td>{$vo.name}</td>
                    <td>{$vo.variable}</td>
                    <td>{$vo.type_text}</td>
                    <td>{$vo.sort}</td>
                    <td>
                        <a href="{:url('admin/document_field/edit', ['id' => $vo['id']])}">{:lang('Edit')}</a>
                        <a onclick="remove('{$vo.id}')" href="#">{:lang('Delete')}</a>
                    </td>
                </tr>
                {/volist}
                {empty name="list"}
                <tr>
                    <td colspan="6" class="text-center">{:lang("No record")}</td>
                </tr>
                {/empty}
            </tbody>
        </table>
      </div>
      <!-- /.tab-pane -->
    </div>
    <!-- /.tab-content -->
  </div>
{/block}

<!-- 自定义js -->
{block name="js"}
<script type="text/javascript">
    function remove(id){
        swal({
          title: "{:lang('Are you sure')}",
          type: 'warning',
          showCancelButton: true,
          confirmButtonColor: '#3085d6',
          cancelButtonColor: '#d33',
          confirmButtonText: "{:lang('Yes')}",
          cancelButtonText: "{:lang('No')}",
        }).then(function(result){
          if (result.value) {
            $.ajax({
                url:"{:Url('admin/document_field/remove')}",
                data:{'id':id},
                type:'post',
                dataType:'json',
                success: function(xhr){
                    if(xhr.code == 200){
                        swal(xhr.msg, "","success").then(function(value){
                            $("#tr_" + id).remove();
                        });
                    }else{
                        swal(xhr.msg, "", "error");
                    }
                }
            })
          }
        })
    }
</script>
{/block}